home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Into His Marvelous Light
/
Into His Marvelous LIGHT.iso
/
ending.dxr
/
00143_Script_Fade In-Out
< prev
next >
Wrap
Text File
|
2001-09-06
|
10KB
|
269 lines
-- Fade In/Out
-- Fades a sprite between two fade values once, multiple times, or indefinitely.
-- v1 - 9 October 1998 by Darrel Plant
on getBehaviorDescription
vDesc = "FADE IN/OUT" & RETURN & RETURN
vDesc = vDesc & "Gives the appearance of a sprite fading in or out."
vDesc = vDesc && "Can be used with text, bitmap, animated GIF, vector"
vDesc = vDesc && "shapes, and Shockwave Flash sprites."
vDesc = vDesc && "Choose whether the sprite should first appear"
vDesc = vDesc && "at maximum (faded in) or minimum (faded out) values,"
vDesc = vDesc && "when the fading should start, the minimum and maximum"
vDesc = vDesc && "fade values, the number of times it should"
vDesc = vDesc && "fade, and how fast it should fade."
vDesc = vDesc && "The fade can be activated automatically in the first frame,"
vDesc = vDesc && "by a click on the sprite, or by sending the sprite a"
vDesc = vDesc && "mFadeActivate message. Set the number of cycles to -1"
vDesc = vDesc && "if you want an endless loop, or 0 if the fade should"
vDesc = vDesc && "happen only once." & RETURN&RETURN
vDesc = vDesc & "PARAMETERS:" & RETURN
vDesc = vDesc & " - Is sprite faded in or out at beginning" & RETURN
vDesc = vDesc & " - Fade activation (automatic, click, message)" & RETURN
vDesc = vDesc & " - Maximum fade value" & RETURN
vDesc = vDesc & " - Minimum fade value" & RETURN
vDesc = vDesc & " - Fade cycles" & RETURN
vDesc = vDesc & " - Fade speed (seconds)" & RETURN&RETURN
vDesc = vDesc & "PERMITTED TYPES:" & RETURN
vDesc = vDesc & "#text, #bitmap, #animgif, #vectorShape, #flash" & RETURN
return vDesc
end getBehaviorDescription
on getBehaviorTooltip
vTip = "Fades a sprite between two fade values" &RETURN
vTip = vTip & "once, multiple times, or indefinitely."&RETURN&RETURN
vTip = vTip &"The fade can be initiated automatically,"&RETURN
vTip=vTip & "by mouse click, or via a message to the sprite."
return vTip
end getBehaviorTooltip
-- PROPERTIES --
property pSprite -- sprite object reference
property pStart -- time last fade started
property pActive -- activity flag for fade action
property pCompleteCycles -- counter for fade cycles
property pFadeDiff -- difference between maximum and minimum fade values
-- author-defined parameters
property pFaded -- does sprite begin fade in or out
property pAuto -- when does fade begin
property pFadeMax -- maximum fade value
property pFadeMin -- minimum fade value
property pCycles -- number of times to repeat fade
property pPeriodBase -- author-defined fade period
property pPeriod -- fade period in milliseconds
-- EVENT HANDLERS --
on beginSprite me
mInitialize me
end beginSprite
on prepareFrame me
mUpdate me
end prepareFrame
on mouseUp me
if pAuto = #click then mActivate me
end mouseUp
-- CUSTOM HANDLERS --
on mInitialize me
-- determine sprite reference
pSprite = sprite (me.spriteNum)
-- flag for fade action
pActive = #off
-- initialize cycle counter
pCompleteCycles = 0.5
-- convert user-set period to milliseconds
pPeriod = pPeriodBase * 1000
-- ensure that maximum is greater than minimum
if pFadeMax < pFadeMin then
-- if max is less than min, swap values
vMax = pFadeMax
pFadeMax = pFadeMin
pFadeMin = vMax
end if
-- determine difference between max and min
pFadeDiff = pFadeMax - pFadeMin
-- if first fade action is 'in', sprite needs to be faded 'out' first
if pFaded = #in then
pSprite.blend = pFadeMin
else
pSprite.blend = pFadeMax
end if
-- activate sprite if automatic activation is set
if pAuto = #automatic then mActivate me
end mInitialize
on mUpdate me
-- only update sprite if active flag is set
if pActive <> #off then
-- derive current value of millisecond timer
vMillis = the milliseconds
-- determine milliseconds elapsed since fade start
vElapsed = vMillis - pStart
-- compare elapsed time to fade period
if vElapsed >= pPeriod then
-- time has elapsed, fade should finish
-- set sprite to value for end of fade action
case pActive of
#in: pSprite.blend = pFadeMax
#out: pSprite.blend = pFadeMin
end case
-- deactivate activity flag
pActive = #off
-- increment cycle counter and reverse if necessary
mCheckCycle me
else
-- scale difference between fade values to elapsed time
vFadeDiff = integer (pFadeDiff * vElapsed / pPeriod)
-- depending on current value of activity flag, set blend
-- to starting point of flag action plus or minus scaled
-- difference between fade values
case pActive of
#in: pSprite.blend = pFadeMin + vFadeDiff
#out: pSprite.blend = pFadeMax - vFadeDiff
end case
end if
end if
end mUpdate
on mActivate me
-- if pFadeDiff (the difference between pFadeMax and pFadeMin) is 0
-- then fade is never activated
if pFadeDiff then
-- start fade actions
-- test whether sprite should fade in or out as first action
case pFaded of
-- intiate fade in action
#in: mFadeIn me
-- initiate fade out action
#out: mFadeOut me
end case
end if
end mActivate
on mCheckCycle me
-- used to determine whether to initiate another fade action
-- this is checked after each fade action
-- set continuation flag
vContinue = FALSE
-- check cycle setting
case pCycles of
-- if value is -1, sprite will cycle forever, set flag to TRUE
-1: vContinue = TRUE
-- if value is 0, sprite should stop after first fade action
0: vContinue = FALSE
otherwise
-- any other value will cycle 1 to 10 times
-- each fade action increments counter by 0.5
pCompleteCycles = pCompleteCycles + 0.5
-- compare counter to total number of cycles
if integer (pCompleteCycles) <= pCycles then
-- if counter is less than numberof cycles, continue fading
vContinue = TRUE
end if
end case
-- if continuation flag has been set, then determine which way to fade
if vContinue then
-- compare current blend value to maximum fade
if pSprite.blend = pFadeMax then
-- if they are equal, fade sprite out
mFadeOut me
else
-- otherwise, fade sprite in
mFadeIn me
end if
end if
end mCheckCycle
on mFadeIn me
mFade me, #in
end mFadeIn
on mFadeOut me, vTarget
mFade me, #out
end mFadeOut
on mFade me, vInOut
-- general-purpose fade handler
-- set activity flag
pActive = vInOut
-- start fade timer
pStart = the milliseconds
end mFade
on mErrorAlert me, vError, vData
-- based on James Newton's error checking procedure
-- determine name of behavior
vBehaviorname = string (me)
delete word 1 of vBehaviorName
delete the last word of vBehaviorName
delete the last word of vBehaviorName
-- convert supporting data
case vData.ilk of
#void: vData = "<void>"
#symbol: vData = "#" & vData
end case
case vError of
-- deal with individual error types
#getPDLError: -- error from property dialog
beep
return [#getPDLError: [#comment: ¼
"CANCEL: Sprite MUST be one of the following member types:" ¼
& RETURN & vData, #format: #symbol, ¼
#range: [#Cancel], #default: #Cancel]]
#runTimeError: -- called if wrong sprite type is detected in beginSprite
alert "CANCEL: Sprite MUST be one of the following member types:" ¼
& RETURN & mPermittedMemberTypes ()
end case
end mErrorAlert
--PUBLIC METHOD
--use this method to send a message to the sprite and initiate
--the Fade In or Out.
--Example:
--sendSprite(1, #mFadeActivate)
on mFadeActivate me
-- message sent to activate sprite if not auto or by click
if pAuto = #message then mActivate me
end mFadeActivate
-- AUTHOR-DEFINED PARAMETERS
on getPropertyDescriptionList me
if not the currentSpriteNum then
-- behavior has been attached to script channel
exit
end if
vMember = sprite (the currentSpriteNum).member
vMemberType = vMember.type
vPermitted = mPermittedMemberTypes ()
if not vPermitted.getPos (vMemberType) then
-- sprite member is not of the correct type
return mErrorAlert (me, #getPDLError, vPermitted)
end if
vPDList = [:]
setaProp vPDList, #pFaded, [#comment: "Fade in or out?", #format: #symbol, ¼
#default: #in, #range: [#in, #out]]
setaProp vPDList, #pFadeMax, [#comment: "Maximum Fade Value", #format: #integer, ¼
#default: 100, #range: [#min: 0, #max: 100]]
setaProp vPDList, #pFadeMin, [#comment: "Minimum Fade Value", #format: #integer, ¼
#default: 0, #range: [#min: 0, #max: 100]]
setaProp vPDList, #pAuto, [#comment: "Start automatically, when clicked," && ¼
"or by message?", #default: #automatic, #format: #symbol, ¼
#range: [#automatic, #click, #message]]
setaProp vPDList, #pCycles, [#comment: "Fade cycles (0 = one" && ¼
"fade only, -1 = repeat forever)", #format: #integer, ¼
#default: 0, #range: [#min: -1, #max:10]]
setaProp vPDList, #pPeriodBase, [#comment: "Time period for fade (seconds)", ¼
#format: #float, #default: 2.0, #range: [#min: .25, #max: 15.0]]
return vPDList
end getPropertyDescriptionList
on mPermittedMemberTypes me
return [#text, #bitmap, #animgif, #vectorShape, #flash]
end mPermittedMemberTypes